package com.ruoyi.aslife.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.aslife.domain.Article;
import com.ruoyi.aslife.service.IAS_ArticleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章信息管理Controller
 * 
 * @author ruoyi
 * @date 2022-12-01
 */
@RestController
@RequestMapping("/system/as_article")
public class ArticleController extends BaseController
{
    @Autowired
    private IAS_ArticleService aS_ArticleService;

    /**
     * 查询文章信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:as_article:list')")
    @GetMapping("/list")
    public TableDataInfo list(Article aS_Article)
    {
        startPage();
        List<Article> list = aS_ArticleService.selectAS_ArticleList(aS_Article);
        return getDataTable(list);
    }

    /**
     * 导出文章信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:as_article:export')")
    @Log(title = "文章信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Article aS_Article)
    {
        List<Article> list = aS_ArticleService.selectAS_ArticleList(aS_Article);
        ExcelUtil<Article> util = new ExcelUtil<Article>(Article.class);
        util.exportExcel(response, list, "文章信息管理数据");
    }

    /**
     * 获取文章信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:as_article:query')")
    @GetMapping(value = "/{aid}")
    public AjaxResult getInfo(@PathVariable("aid") Long aid)
    {
        return success(aS_ArticleService.selectAS_ArticleByAid(aid));
    }

    /**
     * 新增文章信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:as_article:add')")
    @Log(title = "文章信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Article aS_Article)
    {
        return toAjax(aS_ArticleService.insertAS_Article(aS_Article));
    }

    /**
     * 修改文章信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:as_article:edit')")
    @Log(title = "文章信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Article aS_Article)
    {
        return toAjax(aS_ArticleService.updateAS_Article(aS_Article));
    }

    /**
     * 删除文章信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:as_article:remove')")
    @Log(title = "文章信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aids}")
    public AjaxResult remove(@PathVariable Long[] aids)
    {
        return toAjax(aS_ArticleService.deleteAS_ArticleByAids(aids));
    }
}
